<script src="/js/commentsRev.js"></script>
<?php Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl.'/js/scrollTo.js'); ?>

<?php $params = array('catId'=>$cat['catId'], 'partnerUrl'=>$partner['url']); ?>    
<?php $this->renderPartial('//partials/partnerMenu', array('partner'=>$partner, 'advertCode'=>$advertCode, 'cat'=>$cat, 'userIsWork'=>$userIsWork, 'relProfiles'=>$relProfiles, 'errorModel'=>$errorModel, 'subCats'=>$subCats,'curent'=>'news','show_tabs'=>1));?> 
<br/>

<?php
    function printSubComments($target, $comments, $level, $countMessagesData) {
        $level++;
          for($i=0; $i<count($comments); $i++) {
            if($target['comId'] == $comments[$i]['parentId']) {
                if($level < 7) {
                     echo '<ul class="comments">';
                } 
                echo '<a style="padding-top:65px;" id="com'.$comments[$i]['comId'].'"></a>';
                echo '<li id="comment'.$comments[$i]['comId'].'">'; 
                echo '<div class="comment_head">';           
                echo '<a id="com'.$comments[$i]['comId'].'"';
                if(!Yii::app()->user->isGuest){ echo 'class="comment_otv"';} 
                echo 'href="#com'.$comments[$i]['comId'].'">#</a>&nbsp;&nbsp;';
                
                echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $comments[$i]['date']).'&nbsp;&nbsp;&nbsp;';
                   $login = !empty($comments[$i]['displayName']) ? $comments[$i]['displayName'] : $comments[$i]['login'];
                echo '<a href="'.Yii::app()->createUrl('user/profile/profile', array('login'=>$comments[$i]['login'])).'">'.$login.'</a>&nbsp;';  
                
                if(!empty($countMessagesData)) {
                    $count=0;
                    foreach ($countMessagesData as $countMessages) : 
                        if($countMessages['userId'] == $comments[$i]['comUid']) {
                            $count = $countMessages['reviews'] + $countMessages['newsComments'] + $countMessages['forumComments'] + $countMessages['revComments'] + $countMessages['blogComments'];
                        }
                    endforeach;

                    echo '<span class="comment_numb">'.$count.'</span>';

                    
                }
               
                echo '  </div> ';   
                
                echo '<div class="comment_body"><p>';
                echo $comments[$i]['text'];
               
                echo'</p> ';
               
                if(!Yii::app()->user->isGuest) :
                  echo '<a href="#comment-form" class="comment_otv">Ответить</a> ';
                endif;
                echo CHtml::hiddenField('', $comments[$i]['comId'], array('class'=>'comId'));
               
               
                echo'</div>';
                printSubComments($comments[$i], $comments, $level, $countMessagesData);
                echo '</li>';
                if($level < 7) echo '</ul>';
            }
        }
       
    }
?>
<div class="padding4020">
<div class="news_singl">
     <div class="news_date"><?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года", $news['date']); ?></div>
    <h1 class="news_title"><?php echo $news['title']; ?></h1>
    
    <?php echo $news['text']; ?>
   
   
</div>
  <?php if(!Yii::app()->user->isGuest) : ?>
                        <a href="#comment-form" style="margin-bottom:20px;" class="comment_otv">Комментировать</a>
                    <?php endif; ?>
</div>
<?php if(!empty($comments)) : ?>
<div class="padding040">

<h2 class="com_head">Комментарии</h2>
</div>
 


 <?php for($i = 0; $i<count($comments); $i++) : ?>
        <?php // if($comments[$i]['isDelegate']) continue; ?>
            <?php if(!$comments[$i]['parentId']) : ?>
            <ul class="comments">
                <a style="padding-top:65px;" id="com<?php echo $comments[$i]['comId']; ?>"></a>
                <li id="comment<?php echo $comments[$i]['comId'];  ?>">
                <div class="comment_head"><a href="#com<?php echo $comments[$i]['comId'];  ?>">#</a>&nbsp;&nbsp;<?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $comments[$i]['date']); ?>&nbsp;&nbsp;&nbsp;
                   
                     <a href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$comments[$i]['login'])); ?>"><?php echo !empty($comments[$i]['displayName']) ? $comments[$i]['displayName'] : $comments[$i]['login']; ?></a>&nbsp;

                    <?php 
                    if(!empty($countMessagesData)) {
                        $count = 0;
                        foreach ($countMessagesData as $countMessages) : 
                            if($countMessages['userId'] == $comments[$i]['comUid']) {
                                $count = $countMessages['reviews'] + $countMessages['newsComments'] + $countMessages['forumComments'] + $countMessages['revComments'] + $countMessages['blogComments'];
                            }
                        endforeach; ?>
                     <span class="comment_numb"><?php echo $count; ?></span>  
                   <?php } ?>


                   
                   
                   
                    </div>    
                        
                    <div class="comment_body"><p><?php echo $comments[$i]['text']; ?></p>
                          <?php if(!Yii::app()->user->isGuest) : ?>
                        <a href="#comment-form" class="comment_otv">Ответить</a>
                    <?php endif; ?>
                         <?php echo CHtml::hiddenField('', $comments[$i]['comId'], array('class'=>'comId')); ?>
                  
                      
                        
                        
                  
                    </div>
                   
                   
                    
                    <?php printSubComments($comments[$i], $comments, 1, $countMessagesData); ?>
                </li>
                </ul> 
            <?php endif; ?>
    <?php endfor; ?>










<?php endif; ?>



<div class="padding4020">
     
    
    
    
               <div  id="comment-form" class="hiddenForm hide">   
<div class="comment_form_cut"></div>
<div  class=" comment_form">
    <?php echo CHtml::beginForm(); ?>
<div style="width:100%;display: inline-block;"><span class="pull-right close_form"></span></div>
<div class="pull-left">
    <div class="user_av_form_rew pull-left">
                <?php if (Yii::app()->user->getState('avatar')) : ?>
                    <img alt="" src="/images/uploads/userAvatars/<?php echo Yii::app()->user->getState('avatar'); ?>" style="height:28px; width:28px;" alt="" />
                <?php else : ?>
                    <img src="/images/prettyImg/default-avatarl.jpg"  style="height:28px; width:28px;" alt="" />
                <?php endif; ?> 
     </div>   
    <?php echo CHtml::activeTextArea($model, 'text', array('class'=>'text_area_comm', 'id'=>'editor')); ?>

</div>

        
        
  <div class="clearfix"></div> 
  
  <div style="height:40px;"></div>
   
    
  <div class="pull-left">
    <?php echo CHtml::submitButton('Добавить комментарий',array('class'=>'bt_submit_review')); ?> 
   </div>
   <div class="pull-right"  style="margin-top:10px;">
    <div  class="subscrible_form_com pull-left " style="display: block;"> 
        <input placeholder="Подписаться на комментарии" id="subscrEmail" class="subscrible_input_com" type="text" value="" name="">    <div class="subscrible_sub" id="submitSubscrWindow"> </div>
    </div>
   </div>
   <div class="clearfix"></div> 
    <?php echo CHtml::activeHiddenField($model, 'parentId', array('value'=>'', 'class'=>'comParentId')); ?><br/>
    <?php echo CHtml::activeHiddenField($model, 'newsId', array('value'=>$news['newsId'])); ?><br/>
    <?php echo CHtml::endForm(); ?>
      
        
</div>
</div>


</div>
